package com.hibikiluler.javalearning.service.impl;

import com.hibikiluler.javalearning.entity.BookCollect;
import com.hibikiluler.javalearning.entity.LearnCollect;
import com.hibikiluler.javalearning.mapper.ItemCollectMapper;
import com.hibikiluler.javalearning.service.ItemCollectService;
import com.hibikiluler.javalearning.util.DateUtils;
import com.hibikiluler.javalearning.util.Result;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.List;


@Service
@Slf4j
public class ItemCollectServiceImpl implements ItemCollectService {

    @Autowired
    private ItemCollectMapper itemCollectMapper;

    @Override
    public Result findCollectLearn(Long userId) {
        List<LearnCollect> learnCollects = itemCollectMapper.findCollectLearn(userId);
        return Result.success("收藏资讯查询成功",learnCollects);
    }

    @Override
    public Result findCollectBook(Long userId) {
        List<BookCollect> bookCollects = itemCollectMapper.findCollectBook(userId);
        return Result.success("收藏书籍查询成功",bookCollects);
    }

    @Override
    public Result insertCollectLearn(LearnCollect learnCollect) {
        learnCollect.setCollectTime(DateUtils.getDateTime());
        itemCollectMapper.insertCollectLearn(learnCollect);
        return Result.success("收藏成功！");
    }

    @Override
    public Result insertCollectBook(BookCollect bookCollect) {
        bookCollect.setCollectTime(DateUtils.getDateTime());
        itemCollectMapper.insertCollectBook(bookCollect);
        return Result.success("收藏成功！");
    }

    @Override
    public Result deleteCollectLearn(LearnCollect learnCollect) {
        itemCollectMapper.deleteCollectLearn(learnCollect);
        return Result.success("取消收藏成功！");
    }

    @Override
    public Result deleteCollectBook(BookCollect bookCollect) {
        itemCollectMapper.deleteCollectBook(bookCollect);
        return Result.success("取消收藏成功！");
    }
}
